#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
typedef struct binarytree
{
	char* arr;
	int size;
}Tree;
char build_tree(Tree* t,int n,int root,char in[], char pre[],int start,int rear)
{
	if (pre[root] == 0||rear<start)
		return;
	t->arr[n] = pre[root];
	t->size++;
	int div = 0;
	int root2 = 0;
	int root1 = 0;
	while (in[div] != pre[root])
	{
		div++;
	}
	int i = start;
	int flag = 0;
	int max = 0;
	for (i; i < div; i++)
	{
		int j = 0;

		for (j; pre[j]!=0; j++)
		{
			if (pre[j] == in[i])
			{
				flag++;
				if (j > max)
					max = j;
				break;
			}
		}
		if (flag == div - start)
		{
			root1 = max;
			break;
		}
	}
	 i = div+1;
	 flag = 0;
	 max = 0;
	for (i; i <= rear; i++)
	{
		int j = 0;

		for (j; pre[j]!=0; j++)
		{
			if (pre[j] == in[i])
			{
				flag++;
				if (j > max)
					max = j;
				break;
			}
		}
		if (flag == rear-div)
		{
			root2 = max;
			break;
		}
	}
	build_tree(t,n*2+1, root1, in, pre, start, div - 1);
    build_tree(t,n*2+2, root2, in, pre, div+1, rear);

}
void BinaryTreePrevOrder(Tree* root,int n)
{
	int i = n;
	if (root->arr[i]<='z' && root->arr[i] >= 'a')
	{
		printf("%c", root->arr[i]);
		BinaryTreePrevOrder(root,2*n+1);
		BinaryTreePrevOrder(root,2*n+2);
	}
	

}
int main()
{
	char arr1[100] = { 0 };
	char arr2[100] = { 0 };
	scanf("%s", arr1);
	scanf("%s", arr2);
	int i = 0;
	while (arr1[i]!=0)
	{
		i++;
	}
	i--;
	Tree t;
	t.arr = (char*)malloc(400);
	t.size = 0;
	build_tree(&t,0,i,arr1, arr2,0,i);
	//printf("%d", t.size);
	BinaryTreePrevOrder(&t, 0);
}